package com.junzhiit.nengji.cms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.TypeService;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.TypeAddVO;
import com.junzhiit.nengji.cms.web.vo.TypeEditVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/type")
public class TypeController extends BaseController {

	@Autowired
	private TypeService typeService;

	@ApiOperation(value = "查询所有分类信息")
	@RequestMapping(method = RequestMethod.GET)
	public ResultVO findAll(String sessionId) {
		return typeService.findAll(sessionId);
	}

	@ApiOperation(value = "查询具体某个分类信息")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findbyid(@PathVariable String id) {
		return typeService.findbyid(id);
	}

	@ApiOperation(value = "查询一二级分类名字")
	@RequestMapping(value = "/all/name", method = RequestMethod.GET)
	public ResultVO getAllName(String sessionId) {
		return typeService.getAllName(sessionId);
	}

	@ApiOperation(value = "查询所有分类名字")
	@RequestMapping(value = "goods/type", method = RequestMethod.GET)
	public ResultVO getGoodsType(String sessionId) {
		return typeService.getGoodsType(sessionId);
	}

	@ApiOperation(value = "增加分类")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO create(TypeAddVO typeAddVO) {
		ResultVO result = new ResultVO();
		AssertUtil.notBlank(typeAddVO.getParentId(), "ParentId is required");
		AssertUtil.notBlank(typeAddVO.getName(), "Name is required");
		result = typeService.add(typeAddVO);
		return result;
	}

	@ApiOperation(value = "删除分类")
	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	public ResultVO delete(@PathVariable String id) {
		return typeService.delete(id);
	}

	@ApiOperation(value = "更新分类")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(TypeEditVO typeEditVO) {
		return typeService.update(typeEditVO);
	}
	
	@ApiOperation(value = "查询所有的商品所有分类(总部商品审核下拉框)")
	@RequestMapping(value = "/select", method = RequestMethod.GET)
	public ResultVO getGoodsAuditType(String shopId) {
		AssertUtil.notBlank(shopId, "shopId is required");
		return typeService.getGoodsAuditType(shopId);
	}
	
	@ApiOperation(value="上传分类图片")
	@RequestMapping(value="/img",method=RequestMethod.PUT)
	public ResultVO updateTypeImage(TypeEditVO typeEditVO){
		AssertUtil.notBlank(typeEditVO.getId(), "id is required");
		return typeService.updateTypeImage(typeEditVO);
	}
	
	@ApiOperation(value="删除上传图片")
	@RequestMapping(value="/img",method=RequestMethod.DELETE)
	public ResultVO deleteTypeImage(String id){
		AssertUtil.notBlank(id, "id is required");
		return typeService.deleteTypeImage(id);
	}

}
